package com.zkzx.company.api.controller.amap;

import com.zkzx.common.exception.BaseException;
import com.zkzx.util.exception.UrilException;
import com.zkzx.util.map.vo.AMapPoiVO;
import com.zkzx.util.map.AMapUtil;
import com.zkzx.util.map.vo.AMapRouteVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RestController
@Api(tags="高德地图API")
@RequestMapping("/aMap")
public class AMapController {

    @Resource
    private AMapUtil aMapUtil;

    /**
     * 高德api 关键字模糊查询
     *
     * @param keyWord   关键字
     * @param city 可选值：城市中文、中文全拼、citycode、adcode
     */
    @GetMapping("/KeywordsAddByLbs/{keyWord}")
    @ResponseStatus(HttpStatus.OK)
    @ApiOperation(value = "高德api 关键字模糊查询", notes = "高德api 关键字模糊查询")
    public List<AMapPoiVO> getKeywordsAddByLbs(@ApiParam(value = "查询关键字") @PathVariable(value = "keyWord") String keyWord,
                                               @ApiParam(value = "可选值：城市中文、中文全拼、") @RequestParam(value = "city", required = false) String city) {

        try {
            return aMapUtil.getKeywordsAddByLbs(keyWord, city);
        }catch (UrilException e){
            throw new com.zkzx.common.exception.BaseException(e.getErrCode(), e.getErrMsg());
        }
    }

    /**
     * 高德地图WebAPI : 驾车路径规划 计算两地之间行驶的距离(米)
     * String origins:起始坐标
     * String destination:终点坐标
     *输入：原坐标:{116.45925,39.910031}，目标坐标:{116.587922,40.081577}
     *输出：25424
     */
    @GetMapping("/distance/{origins}/{destination}")
    @ResponseStatus(HttpStatus.OK)
    @ApiOperation(value = "高德api 驾车路径规划", notes = "高德api 驾车路径规划")
    public AMapRouteVO distance(@ApiParam(value = "起始坐标") @PathVariable(value = "origins") String origins,
                                @ApiParam(value = "终点坐标") @PathVariable(value = "destination")
                                   String destination) {

        try {
            return aMapUtil.distance(origins, destination);
        }catch (UrilException e){
            throw new BaseException(e.getErrCode(), e.getErrMsg());
        }
    }

}
